<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>现金卡面值列表</title>
    <!--{include file='comm/comm_cal.tpl'}-->
    <!--{include file="comm/icheck.tpl"}-->
    <!--{include file='comm/comm_pic.tpl'}-->
</head>
<body>

<div class="container">

    <div class="comm_content">

        <table id="flex" style="display:none"></table>

    </div>

</div>

<!---新增代金卡弹出框start-->
<div id="pop" style="display: none;">

    <div class="panel">

        <div class="panel-body">

            <form id="item_form" onsubmit="return false;" class="form-horizontal">

                <input type="hidden" id="face_value_id" name="face_value_id" value="0">

                <div class="form-group">
                    <label class="col-sm-4 control-label" for="face_value">
                        <span class="red">*</span>
                        现金卡面值：
                    </label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control w150" placeholder="请输入现金卡面值"  id="face_value" name="face_value" />
                    </div>

                    <label class="col-sm-4 control-label" for="face_value" style="margin-top: 10px;">
                        <span class="red">*</span>
                        现金卡描述：
                    </label>
                    <div class="col-sm-8" style="margin-top: 10px;">
                        <input type="text" class="form-control w160" placeholder="请输入现金卡描述信息"  id="card_info" name="card_info" />
                    </div>
                </div>

            </form>
        </div>
    </div>
</div>

<script>
$("#flex").flexigrid({
    url:"/invokingAjax-backend/company/cashCard.ajax?operFlg=1",
    dataType: "json",
    colModel : [
        {display: "操作", width : 100, align:"center"},
        {display: "现金卡序号", name : "face_value_id", sortable : true,width : 80,align:"left"},
        {display: "现金卡面值", name: "face_value", sortable : true, width : 150,align:"left"},
        {display: "现金卡描述", name: "card_info", sortable : true, width : 150,align:"left"}
    ],
    buttons : [
        {name: "添加", bclass: "add", onpress : "cardList.edit.open"},
        {separator: true},
        {name: "删除", bclass: "delete", onpress : "cardList.del.check"},
        {separator: true},
        {name: "全选", bclass: "checkAll", onpress : "E.checkAllList"},
        {separator: true},
        {name: "取消全选", bclass: "cancelCheckAll", onpress : "E.cancelCheckAllList"}

    ],
    sortname: "face_value_id, face_value",
    sortorder: "desc",
    usepager: true,
    rp: 10,
    useRp: true,
    showTableToggleBtn: true,
    onSubmit: function() {
        var dt = $('#search_form').serializeArray();
        $("#flex").flexOptions({params: dt});
        return true;
    }
});

var cardList ={

    face_value_id:'',//现金卡生产单ID

    //添加或修改代金卡
    edit: {

        open: function( face_value_id ) {

            if (!face_value_id) {
                face_value_id = 0;
            } else {
                cardList.face_value_id = face_value_id;
            }

            E.popup.open({
                id: 'pop',
                title: face_value_id == 0 ? '添加现金卡面值' : '修改现金卡面值',
                css: 'width: 600px;',
                btnName: '保存',
                btnCall: 'cardList.edit.check();'
            });

            $('.square-checkbox').iCheck({
                checkboxClass: 'icheckbox_square-blue',
                radioClass: 'iradio_square-blue',
                increaseArea: '20%' // optional
            });

            if (face_value_id > 0) {

                E.ajax_get({
                    url: '/invokingAjax-backend/company/cashCard.ajax?operFlg=2',
                    data: {
                        face_value_id: face_value_id
                    },
                    call: function( o ) {

                        if (o.code == 200) {
                            $('#face_value_id').val(o.data.face_value_id);
                            $('#face_value').val(o.data.face_value);
                            $('#card_info').val(o.data.card_info);

                        }

                    }
                });

            }

        },

        check: function() {

            this.dt = E.getFormValues('item_form');
            var error_msg = '';

            if (E.isEmpty(this.dt.face_value))
                error_msg += '现金卡面值不能为空<br/>';
            if (E.isEmpty(this.dt.card_info))
                error_msg += '现金卡描述信息不能为空<br/>';

            if (error_msg != '') {
                E.alert(error_msg);
            } else {

                if (cardList.face_value_id){
                    E.confirm('您确认修改现金卡面值吗？', 'cardList.edit.execute');
                } else {
                    E.confirm('您确认添加现金卡面值吗？', 'cardList.edit.execute');
                }


            }

        },

        execute: function() {

            E.loadding.open('正在保存，请稍候...');

            E.ajax_post({
                url: '/invokingAjax-backend/company/cashCard.ajax?operFlg=100&act=edit',
                data: this.dt,
                call: 'cardList.edit.result'
            });

        },

        result: function( o ) {

            E.loadding.close();

            if (o.code == 200) {

                if (this.dt.face_value_id > 0) {
                    E.popup.close();
                } else {
                    document.getElementById('item_form').reset();
                }

                E.alert(o.message, 2, 'cardList.load');
            } else {
                E.alert(o.message);
            }

        }

    },

    del: {

        p_array: '',

        check: function() {

            var p_obj = $('#flex').find('tr.trSelected');
            if (p_obj.length == 0) {
                E.alert('请选择要删除的现金卡面值');
            } else {

                var temp_array = new Array();
                var error_flg = 0;

                $.each(p_obj, function(k, v) {
                    var id = $(v).attr('id').replace('row', '');

                    temp_array.push($(v).attr('id').replace('row', ''));
                });


                this.p_array = temp_array;
                E.confirm('您确认要删除选中的现金卡面值吗？', 'cardList.del.execute');


            }

        },

        execute: function() {
            E.loadding.open('正在删除，请稍候...');
            E.ajax_post({
                url: '/invokingAjax-backend/company/cashCard.ajax?operFlg=100&act=del',
                data: {
                    p_array: this.p_array
                },
                call: 'cardList.del.result'
            });
        },

        result: function( o ) {

            E.loadding.close();
            if (o.code == 200) {
                E.alert('删除成功', 2, 'cardList.load');
            } else {
                E.alert(o.message);
            }

        }

    },

    //重新加载表格
    load: function() {
        $("#flex").flexReload();
    }


};


</script>


</body>
</html>